package cn.jtfadmin.cms.domain.entity;

import cn.jtfadmin.base.data.jpa.domain.entity.BaseEntity;
import cn.jtfadmin.base.filesystem.annos.File;
import cn.jtfadmin.base.lang.common.domain.entity.TreeEntity;
import cn.jtfadmin.base.lang.enums.FileType;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.stereotype.Component;
import org.springframework.util.comparator.Comparators;

import javax.persistence.*;
import java.io.Serializable;

/**
 * cms 页面信息
 * @author jtf
 * @since 0.0.2
 */
@Getter
@Setter
@Entity
@Table(name = "cms_menu")
public class CmsMenuEntity extends BaseEntity implements TreeEntity, Comparable<CmsMenuEntity> {


    /**
     * 标题 head <meta name="title" content="title"/>
     */
    @Column(name = "title")
    protected String title;

    /**
     * 关键字 head <meta name="keywords" content="title"/>
     */
    @Column(name = "keywords")
    protected String keywords;

    /**
     * 页面描述 head <meta name="description" content="title"/>
     */
    @Column(name = "description")
    protected String description;


    /**
     * 排序
     */
    @Column(name = "sort")
    protected Integer sort;

    /**
     * 菜单名称
     */
    @Column(name = "name")
    protected String name;

    /**
     * 跳转链接
     */
    @Column(name = "url")
    protected String url;

    /**
     * 内容html
     */
    @Column(name = "content_html")
    @Lob
    protected String contentHtml;

    /**
     * 内容text
     */
    @Column(name = "content_text")
    @Lob
    protected String contentText;


    /**
     * logo
     *
     */
    @Column(name = "logo")
    @File(dirName = "cms_menu_logo", describe = "cms 菜单logo", fileType = FileType.IMAGE)
    protected String logo;

    /**
     * logo
     *
     */
    @Column(name = "banners")
    @File(dirName = "cms_menu_banners", describe = "cms 轮播logo", fileType = FileType.IMAGE)
    protected String banners;

    /**
     * 是否展示子菜单
     */
    @Column(name = "show_children_menu")
    protected Boolean showChildrenMenu;

    @Column(name = "parent_id")
    protected String parentId;

    @Column(name = "parent_ids")
    protected String parentIds;


    @ManyToOne()
    @JoinColumn(name = "cms_id", nullable = false)
    protected CmsEntity cms;

    /**
     * js 增强
     */
    @Column(name = "script_add")
    @Lob
    protected String scriptAdd;

    /**
     * css 增强
     */
    @Column(name = "style_add")
    @Lob
    protected String styleAdd;

    @Override
    public int compareTo(CmsMenuEntity o) {
        return Comparators.nullsLow().compare(sort,o.sort);
    }
}
